module compare(phrase0, phrase1, checkguess, guess, result, whoshome0, whoshome1, clock50);

input checkguess;
input [7:0] guess;
output result;
reg result;
input[127:0] phrase0;
input[127:0] phrase1;
output[15:0] whoshome0;
reg[15:0] whoshome0;
output[15:0] whoshome1;
reg[15:0] whoshome1;
input clock50;

reg[5:0] s;
reg[5:0] ns;
reg found;

parameter before = 5'd00;

parameter check00 = 5'd01;
parameter check01 = 5'd02;
parameter check02 = 5'd03;
parameter check03 = 5'd04;
parameter check04 = 5'd05;
parameter check05 = 5'd06;
parameter check06 = 5'd07;
parameter check07 = 5'd08;
parameter check08 = 5'd09;
parameter check09 = 5'd10;
parameter check0A = 5'd11;
parameter check0B = 5'd12;
parameter check0C = 5'd13;
parameter check0D = 5'd14;
parameter check0E = 5'd15;
parameter check0F = 5'd16;

parameter check10 = 5'd17;
parameter check11 = 5'd18;
parameter check12 = 5'd19;
parameter check13 = 5'd20;
parameter check14 = 5'd21;
parameter check15 = 5'd22;
parameter check16 = 5'd23;
parameter check17 = 5'd24;
parameter check18 = 5'd25;
parameter check19 = 5'd26;
parameter check1A = 5'd27;
parameter check1B = 5'd28;
parameter check1C = 5'd29;
parameter check1D = 5'd30;
parameter check1E = 5'd31;
parameter check1F = 5'd32;

parameter after = 5'd33;

always @(*)
begin
	case(s)
		before:
		begin
			whoshome0 = 16'b0000_0000_0000_0000;
			whoshome1 = 16'b0000_0000_0000_0000;
			found = 1'b0;
		end
		
		check00:
		begin
			if(phrase0[7:0] == guess)
			begin
				whoshome0[0] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[0] = 1'b0;
			end
		end
		check01:
		begin
			if(phrase0[15:8] == guess)
			begin
				whoshome0[1] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[1] = 1'b0;
			end
		end
		check02:
		begin
			if(phrase0[23:16] == guess)
			begin
				whoshome0[2] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[2] = 1'b0;
			end
		end
		check03:
		begin
			if(phrase0[31:24] == guess)
			begin
				whoshome0[3] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[3] = 1'b0;
			end
		end
		check04:
		begin
			if(phrase0[39:32] == guess)
			begin
				whoshome0[4] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[4] = 1'b0;
			end
		end
		check05:
		begin
			if(phrase0[47:40] == guess)
			begin
				whoshome0[5] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[5] = 1'b0;
			end
		end
		check06:
		begin
			if(phrase0[55:48] == guess)
			begin
				whoshome0[6] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[6] = 1'b0;
			end
		end
		check07:
		begin
			if(phrase0[63:56] == guess)
			begin
				whoshome0[7] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[7] = 1'b0;
			end
		end
		check08:
		begin
			if(phrase0[71:64] == guess)
			begin
				whoshome0[8] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[8] = 1'b0;
			end
		end
		check09:
		begin
			if(phrase0[79:72] == guess)
			begin
				whoshome0[9] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[9] = 1'b0;
			end
		end
		check0A:
		begin
			if(phrase0[87:80] == guess)
			begin
				whoshome0[10] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[10] = 1'b0;
			end
		end
		check0B:
		begin
			if(phrase0[95:88] == guess)
			begin
				whoshome0[11] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[11] = 1'b0;
			end
		end
		check0C:
		begin
			if(phrase0[103:96] == guess)
			begin
				whoshome0[12] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[12] = 1'b0;
			end
		end
		check0D:
		begin
			if(phrase0[111:104] == guess)
			begin
				whoshome0[13] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[13] = 1'b0;
			end
		end
		check0E:
		begin
			if(phrase0[119:112] == guess)
			begin
				whoshome0[14] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[14] = 1'b0;
			end
		end
		check0F:
		begin
			if(phrase0[127:120] == guess)
			begin
				whoshome0[15] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome0[15] = 1'b0;
			end
		end
		
		check10:
		begin
			if(phrase1[7:0] == guess)
			begin
				whoshome1[0] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[0] = 1'b0;
			end
		end
		check11:
		begin
			if(phrase1[15:8] == guess)
			begin
				whoshome1[1] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[1] = 1'b0;
			end
		end
		check12:
		begin
			if(phrase1[23:16] == guess)
			begin
				whoshome1[2] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[2] = 1'b0;
			end
		end
		check13:
		begin
			if(phrase1[31:24] == guess)
			begin
				whoshome1[3] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[3] = 1'b0;
			end
		end
		check14:
		begin
			if(phrase1[39:32] == guess)
			begin
				whoshome1[4] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[4] = 1'b0;
			end
		end
		check15:
		begin
			if(phrase1[47:40] == guess)
			begin
				whoshome1[5] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[5] = 1'b0;
			end
		end
		check16:
		begin
			if(phrase1[55:48] == guess)
			begin
				whoshome1[6] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[6] = 1'b0;
			end
		end
		check17:
		begin
			if(phrase1[63:56] == guess)
			begin
				whoshome1[7] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[7] = 1'b0;
			end
		end
		check18:
		begin
			if(phrase1[71:64] == guess)
			begin
				whoshome1[8] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[8] = 1'b0;
			end
		end
		check19:
		begin
			if(phrase1[79:72] == guess)
			begin
				whoshome1[9] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[9] = 1'b0;
			end
		end
		check1A:
		begin
			if(phrase1[87:80] == guess)
			begin
				whoshome1[10] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[10] = 1'b0;
			end
		end
		check1B:
		begin
			if(phrase1[95:88] == guess)
			begin
				whoshome1[11] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[11] = 1'b0;
			end
		end
		check1C:
		begin
			if(phrase1[103:96] == guess)
			begin
				whoshome1[12] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[12] = 1'b0;
			end
		end
		check1D:
		begin
			if(phrase1[111:104] == guess)
			begin
				whoshome1[13] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[13] = 1'b0;
			end
		end
		check1E:
		begin
			if(phrase1[119:112] == guess)
			begin
				whoshome1[14] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[14] = 1'b0;
			end
		end
		check1F:
		begin
			if(phrase1[127:120] == guess)
			begin
				whoshome1[15] = 1'b1;
				found = 1'b1;
			end
			else
			begin
				whoshome1[15] = 1'b0;
			end
		end
		
		after:
		begin
			if(found == 1'b1)
				result = 1'b1;
			else result = 1'b0;
		end
	endcase
end

always@(posedge clock50)
begin
	s <= ns;
end

always @(*)
begin
	case(s)
		before:
		begin
			if(checkguess == 1'b0)
				ns = before;
			else ns = check00;
		end
		
		check00:
		begin
			ns = check01;
		end
		check01:
		begin
			ns = check02;
		end
		check02:
		begin
			ns = check03;
		end
		check03:
		begin
			ns = check04;
		end
		check04:
		begin
			ns = check05;
		end
		check05:
		begin
			ns = check06;
		end
		check06:
		begin
			ns = check07;
		end
		check07:
		begin
			ns = check08;
		end
		check08:
		begin
			ns = check09;
		end
		check09:
		begin
			ns = check0A;
		end
		check0A:
		begin
			ns = check0B;
		end
		check0B:
		begin
			ns = check0C;
		end
		check0C:
		begin
			ns = check0D;
		end
		check0D:
		begin
			ns = check0E;
		end
		check0E:
		begin
			ns = check0F;
		end
		check0F:
		begin
			ns = check10;
		end
		
		check10:
		begin
			ns = check11;
		end
		check11:
		begin
			ns = check12;
		end
		check12:
		begin
			ns = check13;
		end
		check13:
		begin
			ns = check14;
		end
		check14:
		begin
			ns = check15;
		end
		check15:
		begin
			ns = check16;
		end
		check16:
		begin
			ns = check17;
		end
		check17:
		begin
			ns = check18;
		end
		check18:
		begin
			ns = check19;
		end
		check19:
		begin
			ns = check1A;
		end
		check1A:
		begin
			ns = check1B;
		end
		check1B:
		begin
			ns = check1C;
		end
		check1C:
		begin
			ns = check1D;
		end
		check1D:
		begin
			ns = check1E;
		end
		check1E:
		begin
			ns = check1F;
		end
		check1F:
		begin
			ns = after;
		end
		
		after:
		begin
			ns = after;
		end
	endcase
end
endmodule